package com.bite.book.service;

//import com.bite.book.dao.BookDao;
import com.bite.book.enums.BookStatusEnum;
import com.bite.book.mapper.BookInfoMapper;
import com.bite.book.mode.BookInfo;
import com.bite.book.mode.PageRequest;
import com.bite.book.mode.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookService {
//    @Autowired
//     private BookDao bookDao;
//    public List<BookInfo> getList() {
//        List<BookInfo> bookInfos = bookDao.mockData();
//        //进行借阅相关的设定；
//        for(BookInfo bookInfo:bookInfos) {
//            if (bookInfo.getStatus() == 1) {
//                bookInfo.setStatusCN("可借阅");
//            }else{
//                bookInfo.setStatusCN("不可借阅");
//            }
//        }
//        return bookInfos;
//    }
    @Autowired
    private BookInfoMapper bookInfoMapper;

    public void addBook(BookInfo bookInfo) {
        bookInfoMapper.addBook(bookInfo);
    }
    //根据页码进行图书页面的返回；
    public ResponseResult<BookInfo> getListByPage(PageRequest pageRequest){
        //1.获得总的图书数；
        Integer count=bookInfoMapper.count();
        //2，获取当前页的数据；
        List<BookInfo> bookInfos=bookInfoMapper.selectBooksByPage(pageRequest);
        //进行借阅相关的设定；
        //即进行二次处理；
        for(BookInfo bookInfo:bookInfos) {
            bookInfo.setStatusCN(BookStatusEnum.getStatuesByCode(bookInfo.getStatus()).getDesc());
//            if (bookInfo.getStatus() == 1) {
//                bookInfo.setStatusCN("可借阅");
//            }else{
//                bookInfo.setStatusCN("不可借阅");
//            }
        }
//        ResponseResult<BookInfo> bookInfoResponseResult=new ResponseResult<>();
//        bookInfoResponseResult.setTotal(count);
//        bookInfoResponseResult.setRecords(bookInfos);
        return  new ResponseResult<>(count,bookInfos,pageRequest);

    }

    public BookInfo queryBookById(Integer bookId) {
         return bookInfoMapper.queryBookById(bookId);
    }

    public void updateBook(BookInfo bookInfo) {
        bookInfoMapper.updateBook(bookInfo);
    }
    public Integer batchDelete(List<Integer> ids){
        return bookInfoMapper.batchDelete(ids);
    }
}
